import React, { Component } from 'react';
import { Button, Table, Modal, Form, Input } from 'antd';
import 'antd/dist/antd.css';
import Tab from './component/table';
import Dialog from './component/dialog';
class App extends Component {
    state = {
        list: [
            { key: "01", name: "wyt", age: "22", address: "114" },
            { key: "02", name: "xixi", age: "23", address: "115" },
            { key: "03", name: "haha", age: "24", address: "116" },
            { key: "04", name: "hehe", age: "25", address: "117" },
        ],
        isUpdata: 0,
        updateKey: 0
    }
    // 删除
    delList = (n) => {
        let dellist = this.state.list.filter(ele => n.key !== ele.key)
        this.setState({
            list: dellist
        })
    }
    // 新增
    addLiat = n => {
        let addlist = [...this.state.list, n]
        console.log(addlist)
        this.setState({
            list: addlist
        })
    }
    editList = (value) => {
        value.key = this.state.updateKey
        let arr = JSON.parse(JSON.stringify(this.state.list))
        this.setState({
            list: arr.map(item => {
                if (item.key == value.key) {
                    return value
                } else {
                    return item
                }
            })
        })
    }
    // 修改
    updateList = n => {
        this.setState({
            updateKey: n.key
        })
        setTimeout(() => {
            this.Dia.form.current.setFieldsValue(n)
        }, 0)
        console.log(n, "upda")


    }
    openDia = () => {
        this.Dia.updataDia()
    }
    isUpdata1 = n => {
        this.setState({
            isUpdata: n
        })
    }
    render() {
        let { list, isUpdata } = this.state
        return (
            <div>
                <Dialog ref={el => this.Dia = el} addLiat={this.addLiat} isUpdata={isUpdata} editList={this.editList}></Dialog>
                <Tab list={list}
                    delList={this.delList}
                    updateList={this.updateList}
                    openDia={this.openDia}
                    isUpdata1={this.isUpdata1}
                ></Tab>
            </div>
        );
    }
}

export default App;